
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>核心线程怎么实现一直存活？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>核心线程怎么实现一直存活？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">在 Java 的 ThreadPoolExecutor 中，什么是核心线程（Core Threads）？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">核心线程是 ThreadPoolExecutor 中设定的最小线程数量（由 corePoolSize 参数定义）。这些线程即使在空闲状态下也不会被终止，会始终保持在线程池中，除非线程池被显式关闭。</div>
          </div>
          <div class="card-source">来源: 1. 核心线程的定义与角色</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当一个新任务提交到 ThreadPoolExecutor 时，它如何决定是否使用核心线程？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当任务被提交到线程池时，ThreadPoolExecutor 会首先尝试将任务分配给核心线程。如果所有核心线程都处于忙碌状态，线程池才会尝试其他策略，例如使用非核心线程或将任务放入工作队列。</div>
          </div>
          <div class="card-source">来源: 2. 核心线程的实现机制 - a. ThreadPoolExecutor 内部机制 - 4. 任务提交</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">维持核心线程始终保持活跃状态带来了哪些主要优点？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">主要优点有三点：1. 减少线程创建和销毁的开销，从而提高系统整体性能；2. 确保线程池能够迅速响应新任务，避免高负载时的延迟；3. 更好地利用系统资源，避免因负载变化而频繁地创建和销毁线程。</div>
          </div>
          <div class="card-source">来源: 3. 核心线程维持活跃的优点</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在 ThreadPoolExecutor 运行期间，是否可以动态调整核心线程的数量？如果可以，应该使用哪个方法？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">可以。通过调用 ThreadPoolExecutor 的 `setCorePoolSize` 方法，可以动态地调整核心线程的数量。</div>
          </div>
          <div class="card-source">来源: 4. 核心线程的管理和配置 - 1. 动态调整核心线程数</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在默认配置下，核心线程会在什么情况下被终止？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在默认情况下，核心线程不会因为空闲而被终止。它们会一直保持活动状态，直到线程池被显式关闭，例如通过调用 `shutdown()` 或 `shutdownNow()` 方法。</div>
          </div>
          <div class="card-source">来源: 4. 核心线程的管理和配置 - 2. 线程池的关闭</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在创建 ThreadPoolExecutor 时，哪个参数直接决定了核心线程的数量？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`corePoolSize` 参数用于定义线程池中的核心线程数量，它通过构造函数传递给 ThreadPoolExecutor。</div>
          </div>
          <div class="card-source">来源: 2. 核心线程的实现机制 - a. ThreadPoolExecutor 内部机制 - 1. 线程池参数配置</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
